local lingyuzhankai = fk.CreateSkill{
    name = "ym2__lingyuzhankai",
}
Fk:loadTranslationTable{
    ["ym2__lingyuzhankai"] = "领域展开",
    [":ym2__lingyuzhankai"] = "<a href = ':Battlefield'>战场技！</a>连招技（其他角色使用牌+你需要使用牌），你可以与前者进入或离开<a href = ':ym2__jiajuncheng'>〖家具城〗</a>。",
    ["#ym2__lingyuzhankai-invoke"] = "是否发动 领域展开，与 %dest 进入或离开〖家具城〗",
    ["@[:]Battlefield"] = "战场",
    [":Battlefield"] = "<b>战场技！</b>——<br>可以令角色进入或离开特定战场的技能，位于战场的角色须执行战场规则，战场不会因战场技！持有者死亡或技能失效而消失，但会被其他战场顶替。"..
    "<br>特别的，特殊战场之间可以共存，例如海洋和岛屿，街道和家具城",

    ["$ym2__lingyuzhankai1"] = "对不起对不起，先借用一下。",
    ["$ym2__lingyuzhankai2"] = "我怎么感觉自己好像来过这里，这到底是为什么。",
}
local Al_U = require "packages/ym_Al/Al_util"
lingyuzhankai:addEffect("viewas",{
    pattern = ".",
    prompt = function (self)
        return "#ym2__lingyuzhankai-invoke::"..Self:getMark("ym2__lingyuzhankai")
    end,
    card_filter = Util.FalseFunc,
    view_as = function (self, player, cards)
        local names, all_names = {} , {}
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if (card.type == Card.TypeBasic or card.type == Card.TypeTrick) and not card.is_derived and not table.contains(all_names, card.name) then
                table.insert(all_names, card.name)
                local to_use = Fk:cloneCard(card.name)
                if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
                (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
                    table.insert(names, card.name)
                end
            end
        end
        if #names == 0 then return nil end
        local card = Fk:cloneCard(names[#names])
        card.skillName = self.name
        return card
    end,
    before_use = function (self, player, use)
        local room = player.room
        local last = room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
            return true
        end, 1)[1]
        if last and last.data.from.id ~= player.id then
            local to = room:getPlayerById(last.data.from.id)
            Al_U.changeBattlefield(room,player,{player,to},"ym2__jiajuncheng",self.name)
        end
        room:setPlayerMark(player,"ym2__lingyuzhankai",0)
        return ""
    end,
    enabled_at_play = function (self, player)
        return player:getMark("ym2__lingyuzhankai") ~= 0
    end,
    enabled_at_response = function (self, player, response)
        return not response and player:getMark("ym2__lingyuzhankai") ~= 0
    end,
})
local spec = {
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(lingyuzhankai.name)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local last = room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
            return true
        end, 1)[1]
        if last and last.data.from.id ~= player.id then
            room:setPlayerMark(player,"ym2__lingyuzhankai",last.data.from.id)
        else
            room:setPlayerMark(player,"ym2__lingyuzhankai",0)
        end
    end,
}
lingyuzhankai:addEffect(fk.CardUsing,spec)
lingyuzhankai:addEffect(fk.CardUseFinished,spec)
lingyuzhankai:addEffect(fk.AfterAskForCardUse,spec)
lingyuzhankai:addEffect(fk.AfterCardsMove,spec)
lingyuzhankai:addEffect(fk.AskForCardUse,spec)

return lingyuzhankai